package utils

import (
	"fmt"
	"strings"
)

func ParseBitPhrase(str string) (int64, error) {
	isRight := false
	var arr []string
	err := fmt.Errorf("ParseBitPhrase string format error str: %s", str)
	if strings.Index(str, ">>") != -1 {
		isRight = true
		arr = Split(str, ">>")
	} else if strings.Index(str, "<<") != -1 {
		isRight = false
		arr = Split(str, "<<")
	} else {
		return 0, err
	}

	if len(arr) != 2 {
		return 0, err
	}

	left := ToInt64(Trim(arr[0]))
	right := ToInt64(Trim(arr[1]))
	if isRight {
		return left >> right, nil
	}
	return left << right, nil
}
